<!--
/**************************************************
* @(#)checkManufacture.jsp
*
* Copyright (c) 2005 Hitrust Technology Inc.
* Developed by SDC, Hitrust.
* All Rights Reserved.
*
* Modify History:
*  v1.00, 2006/02/08, SimonyiPeng
*  1) first release
/**************************************************
-->

<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ page import="com.hitrust.gs.business.GSManufactureProcessor"%>
<%@ page import="com.hitrust.gs.bean.GSManufactureBean"%>
<%@ include file="../../common.jsp" %>
<SCRIPT language="JavaScript" src="<%=root%>/js/common.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=root%>/js/string.js"></SCRIPT>


<%

//为了满足在产品查询页面同时选择多个产品的时候也能准确地定位供应商,本页面必须支持多行的查询
boolean isManufactureExist = false;
GSManufactureBean bean = null;
String rowNumBuff = request.getParameter("rownum");
String concentricityIdBuff = request.getParameter("concentricityid");
String deptid=request.getParameter("deptid");
/*
System.out.println("================================");
System.out.println(rowNumBuff);
System.out.println("================================");
System.out.println(concentricityIdBuff);
System.out.println("================================");
*/

LoginContext lcontext=(LoginContext)session.getAttribute(GSBaseConstants.LOGIN);
GSUniteGwProcessor unitepro=new GSUniteGwProcessor();
ArrayList warelist=unitepro.getBzwzAndTmpWareHouse(lcontext.getLoginWarehouseCode());
ArrayList rowNumAry = new ArrayList();
ArrayList concentricityIdAry = new ArrayList();
java.util.StringTokenizer st = null;
st = new StringTokenizer(rowNumBuff,",");
while(st.hasMoreElements()){
	rowNumAry.add(st.nextElement());
}
st = new StringTokenizer(concentricityIdBuff,",");
while(st.hasMoreElements()){
	concentricityIdAry.add(st.nextElement());
}



String manufactureId = null;
String manufactureName = null;
String quantUnit = null;
String manufactureUnitPrice = null;
String spec = null;
String type = null;
String brand = null;
String quantunit = null;
String period = null;
String mode=null;
boolean bool = false;

String msg="集中编码输入不正确，请输入十四位的集中编码...";
GSManufactureProcessor processor = new GSManufactureProcessor ();
%>


<script language='javascript'>	
	function onsubmit(){
		<%for(int index=0;index<rowNumAry.size();index++){%>
		<%
			String concentricityId = (String)concentricityIdAry.get(index);
			String rowNum = (String)rowNumAry.get(index);
			GSManufactureBean tBean = processor.getManufactureForOrderInput(concentricityId,warelist);
			ArrayList provList = processor.getProviderSimpleByconcentricityid(concentricityId,deptid);
			if(tBean != null && provList != null && provList.size() != 0){
				concentricityId = tBean.getGs_concentricity();
				manufactureName = tBean.getGs_manufacture_name();
				quantUnit = tBean.getGs_quant_unit();
				manufactureUnitPrice = StringUtils.formatEDouble(tBean.getGs_manufacture_unitprice(),4);
				spec = StringUtils.escapeXML(tBean.getGs_manufacture_spec());
				type = tBean.getGs_manufacture_type();
				quantunit = tBean.getGs_quant_unit();
				brand = tBean.getGs_manufacture_brand();
				period = tBean.getGs_quality_assure_period();
				mode=tBean.getGs_balance_mode();				
				bool = true;
				GSOrderCategoryDAO dao= new GSOrderCategoryDAO();	
			    if(dao.queryProductCategory(concentricityId,tBean.getGs_provider_id())){
			    	bool = true;
			    	if(dao.queryProductByOrderCategory(concentricityId,tBean.getGs_provider_id(),deptid)){
			    		msg="该集中编码产品对应的供应商不是仓库指定的！";
			    		bool = false;
			    	}else{
			    		if(dao.queryProductBrandOfHave()){
			    			if(dao.queryProductBrandIsCenter(concentricityId)){
			    				if(dao.queryProductBrand(concentricityId,deptid)){
									msg="不能申购，请联系物资公司！";
									bool = false;
								}
			    			}
			    		}
			    	}
 	
			    }else{
		    		if(dao.queryProductBrandOfHave()){
		    			if(dao.queryProductBrandIsCenter(concentricityId)){
		    				if(dao.queryProductBrand(concentricityId,deptid)){
								msg="不能申购，请联系物资公司！";
								bool = false;
							}
		    			}
		    		}
		    	}
			    
				
			}
		%>	
		
		if(<%=bool%>){
			var provId;	
			var provShortName;
			var concentricityId;
			var manufactureId;
			var unitPrice;
            var balancemode;
			var providerlist = parent.document.getElementById("providerid");
			var pricebuffer = "";
			var s="";
			var provid = parent.document.getElementById("providerid"+<%=rowNum%>);
			for(j=1;j<provid.length;j++)
			{
				provid.remove(j);
			}
			<%
				for(int x=0;x<provList.size();x++){
			%>
					provId = "<%=((String[])provList.get(x))[0]%>";
					provShortName = "<%=((String[])provList.get(x))[1]%>";
					concentricityId = "<%=((String[])provList.get(x))[2]%>";
					manufactureId = "<%=((String[])provList.get(x))[3]%>";
					unitPrice = "<%=((String[])provList.get(x))[4]%>";
                    balancemode = "<%=((String[])provList.get(x))[5]%>";
					parent.document.getElementById("manufactureid"+<%=rowNum%>).value = manufactureId;
                    if(balancemode=='<%=GSBaseConstants.BALANCE_MODE1%>'){
                        s="<%=DefineDic.getBalanceMode(GSBaseConstants.BALANCE_MODE1)%>";
                    }else{
                        s="<%=DefineDic.getBalanceMode(GSBaseConstants.BALANCE_MODE2)%>";
                    }
					var tempoption=new Option(provShortName,provId);
					provid.options[provid.length] = tempoption;
					pricebuffer = pricebuffer + provId + ":" + unitPrice + ":" + concentricityId + ":" + manufactureId +":"+balancemode+":"+s+"|";
					parent.document.getElementById("pricebuffer"+<%=rowNum%>).value = pricebuffer;
			<%
				}
			%>

						
			parent.document.getElementById("concentricityid"+<%=rowNum%>).value = '<%=concentricityId%>';
			parent.document.getElementById("manufacturename"+<%=rowNum%>).innerHTML="<div align='center' class='txt_content'><a href='<%=response.encodeURL(root+"/A110104.do")%>?concentricityId="+"<%=concentricityId%>"+"' target='_blank'>"+"<%=manufactureName%>"+"</a></div>";


			parent.document.getElementById("spec"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=spec%>'+"</div>";
			parent.document.getElementById("type"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=type%>'+"</div>";
			parent.document.getElementById("brand"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=brand%>'+"</div>";
			parent.document.getElementById("period"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=period%>'+"</div>";
			parent.document.getElementById("quantunit"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=quantunit%>'+"</div>";

			//为确认提示预备值
			if(parent.document.getElementById("manufacturename_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturename_"+<%=rowNum%>).value = "<%=manufactureName%>";
			if(parent.document.getElementById("manufacturespec_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturespec_"+<%=rowNum%>).value = "<%=spec%>";
			if(parent.document.getElementById("manufacturetype_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturetype_"+<%=rowNum%>).value = "<%=type%>";
			if(parent.document.getElementById("manufacturebrand_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturebrand_"+<%=rowNum%>).value = "<%=brand%>";
			if(parent.document.getElementById("period_"+<%=rowNum%>)!=null)
				parent.document.getElementById("period_"+<%=rowNum%>).value = "<%=period%>";				
			if(parent.document.getElementById("manufacturequantunit_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturequantunit_"+<%=rowNum%>).value = "<%=quantunit%>";
		}
		else{
			parent.document.getElementById("concentricityid"+<%=rowNum%>).value = '';
			//parent.document.getElementById("concentricityid_"+<%=rowNum%>).value = '';
			parent.document.getElementById("manufacturename"+<%=rowNum%>).innerHTML = '';

			parent.document.getElementById("spec"+<%=rowNum%>).innerHTML = '';
			parent.document.getElementById("type"+<%=rowNum%>).innerHTML = '';
			parent.document.getElementById("brand"+<%=rowNum%>).innerHTML = '';
			parent.document.getElementById("period"+<%=rowNum%>).innerHTML = '';
			parent.document.getElementById("quantunit"+<%=rowNum%>).innerHTML = '';

			//为确认提示清理预备值
			if(parent.document.getElementById("manufacturename_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturename_"+<%=rowNum%>).value = "";
			if(parent.document.getElementById("manufacturespec_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturespec_"+<%=rowNum%>).value = "";
			if(parent.document.getElementById("manufacturetype_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturetype_"+<%=rowNum%>).value = "";
			if(parent.document.getElementById("manufacturebrand_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturebrand_"+<%=rowNum%>).value = "";
			if(parent.document.getElementById("period_"+<%=rowNum%>)!=null)
				parent.document.getElementById("period_"+<%=rowNum%>).value = "";				
			if(parent.document.getElementById("manufacturequantunit_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturequantunit_"+<%=rowNum%>).value = "";
						
			alert('<%=msg%>');
			<%System.out.println(rowNum);%>
		}
		<%}%>
		return  false;
	}
</script>
<%@page import="com.hitrust.gs.business.GSUniteGwProcessor"%>
<%@page import="system.LoginContext"%>
<html>
<body onLoad="onsubmit();"></body>
</html>


